<template>
  <div id="weihu">
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px " class="demo-ruleForm">
      <h3 style="text-align: left;padding-left: 5%; " >商户资料维护</h3><br>
      <el :visible.sync="makeFormVisible"  >
        <!-- 图片上传 -->
        <el-form-item label="门店头像" prop="img" style="width: 50%;">
          <el-upload
              class="avatar-uploader"
              action="https://jsonplaceholder.typicode.com/posts/"
              :show-file-list="false"
              :on-success="handleAvatarSuccess"
              :before-upload="beforeAvatarUpload">
            <img v-if="imageUrl" :src="imageUrl" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>


        <el-form-item label="门店名称" prop="userName" style="width: 50%;">
          <el-input v-model="ruleForm.userName" ></el-input>
        </el-form-item>

        <el-form-item label="门店电话" prop="userPhone" style="width: 50%;">
          <el-input v-model="ruleForm.userPhone"></el-input>
        </el-form-item>



        <el-form-item label="门店地址" prop="merchantAddr" style="float: left 20px;">
          <el-select v-model="ruleForm.user_name" clearable placeholder="请选择">
            <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
            </el-option>
          </el-select>


          3


          <el-select v-model="value" clearable placeholder="请选择">
            <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
            </el-option>
          </el-select>

          <el-select v-model="value" clearable placeholder="请选择">
            <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
            </el-option>
          </el-select>

          <el-select v-model="value" clearable placeholder="请选择">
            <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
            </el-option>
          </el-select>


        </el-form-item>


        <el-form-item label="详细地址" prop="phone" style="width: 50%;">
          <el-input v-model="ruleForm.phone"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" style="float: height: 20px ; width: 320px ; " @click="submitForm(ruleForm)">修改</el-button>
        </el-form-item>
      </el>
    </el-form>
  </div>
</template>

<script>


export default {
  data() {
    return {

      ruleForm:[{}],
      makeFormVisible:false,

    }
  },
  methods: {

    // 图片上传
    handleAvatarSuccess(res, file) {
      this.imageUrl = URL.createObjectURL(file.raw);
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === 'image/jpeg';
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error('上传头像图片只能是 JPG 格式!');
      }
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!');
      }
      return isJPG && isLt2M;
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // 提交表单数据
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },


    async dsahgdasuguy(){
      //回显
      let uid=sessionStorage.getItem("token")
      this.makeFormVisible = true
      const {data: res} = await this.$http.post(`/buy/customer/dsahgdasuguy/${uid}`)
      this.ruleForm=res

    },
    //点击修改成功
    async submitForm(data){
      let userId=sessionStorage.getItem("token")
      const {data: res} = await this.$http.post(`/buy/customer/xg`,data)
      this.dsahgdasuguy()
      console.log(1,res)
      this.$message({
        makeFormVisible: true,
        message:'修改成功',
        type:'success'
      });
      this.makeFormVisible=false
    },

  },
  created() {
    this.dsahgdasuguy()
  }
}
</script>

<style>



/* 图片上传 */
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 150px;
  height: 150px;
  line-height: 150px;
  text-align: center;
}
.avatar {
  width: 150px;
  height: 150px;
  display: block;
}
</style>
